<template>
  <view class="dialog" v-if="visible">
    <view class="dialog-content">
      <view class="dialog-header">
        <text class="dialog-title">{{ title }}</text>
        <text class="dialog-close" @click="close">x</text>
      </view>
      <view class="dialog-body">
        <view class="dialog-container">
          <slot></slot>
        </view>
      </view>
      <view class="dialog-footer">
        <button class="dialog-button" @click="confirm">{{ confirmButtonText }}</button>
        <button class="dialog-button" @click="cancel">{{ cancelButtonText }}</button>
      </view>
    </view>
  </view>
</template>

<script>export default {
  props: {
    title: {
      type: String,
      default: '提示'
    },
    visible: {
      type: Boolean,
      default: false
    },
    confirmButtonText: {
      type: String,
      default: '确定'
    },
    cancelButtonText: {
      type: String,
      default: '取消'
    }
  },
  methods: {
    close() {
      this.$emit('update:visible', false);
    },
    confirm() {
      this.$emit('confirm');
      this.close();
    },
    cancel() {
      this.$emit('cancel');
      this.close();
    }
  }
};
</script>
<style>
.dialog {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
}

.dialog-content {
  background-color: white;
  border-radius: 10px;
  overflow: hidden;
  width: 80%;
  max-width: 600px;
  display: flex;
  flex-direction: column;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid #eee;
}

.dialog-title {
  font-size: 24px;
  font-weight: bold;
}

.dialog-close {
  font-size: 24px;
  cursor: pointer;
}

.dialog-body {
  padding: 0; /* 清除默认 padding */
  flex: 1;   /* 让 body 占满剩余空间 */
  overflow: auto; /* 如果内容太多允许滚动 */
}

.dialog-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  padding: 20px;
  border-top: 1px solid #eee;
}

.dialog-button {
  margin-left: 10px;
  padding: 3px 20px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}

.dialog-button:first-child {
  background-color: #ffcc00;
}

.dialog-button:last-child {
  background-color: #ccc;
}
</style>
